﻿package skyExt
{
	import flash.events.Event;
	import flash.events.EventDispatcher;	
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.net.URLRequest;
	import flash.display.Stage;
	
	public class SkyGameLoader extends Object 
	{

		private static var theParent:Stage;
		
		private static var swfURL:String;
	
		/*
			描述：加载新的SWF文件，老的swf会被从flash上移除，并且不在能访问老flash里面的内容
			
			参数1:  舞台对象
			参数2：	指定下载目标的swf名字和地址
		*/	
		static public function load(p:Stage , targetUrl:String ,version:int)
		{
			theParent = p;
			
			var swfLoader:Loader = new Loader();
			
			var swfURL:String = targetUrl;
			
			var swfURLReq:URLRequest = new URLRequest(swfURL);
			
			swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); 			
			
			swfLoader.load(swfURLReq);

		}
		
		static function loadComplete(e:Event):void {
			trace("load Complete");
			theParent.removeChildAt(0);
			
			theParent.addChild(e.target.content);
		}
	}
}
